<!DOCTYPE html>
<html>
<head>
    {include file="_Fragment/meta" /}
    <link rel="stylesheet" href="/static/pear/component/pear/css/pear.css" />
</head>
<body class="pear-container">

<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-form-item layui-inline">
                    <div class="layui-input-inline">
                        <select name="task_id">
                            <option value="">积分任务</option>
                            {volist name="task" id="vo"}
                            <option value="{$vo.id}">{$vo.title}</option>
                            {/volist}
                        </select>
                    </div>
                </div>

                <div class="layui-form-item layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" name="title" placeholder="工号|姓名" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" name="time" id="date" placeholder="时间（范围）" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item layui-inline">
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="user-query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card">
    <div class=" layui-tab layui-tab-card">
        <ul class="layui-tab-title">
            <li>
                <a href="/IntegralRecord/task">任务明细</a>
            </li>
            <li class="layui-this">用户明细</li>
        </ul>
        <div class="layui-card-body">
            <table id="user-table" lay-filter="user-table"></table>
        </div>
    </div>
</div>
<script type="text/html" id="user-toolbar">
    <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="import">
        <i class="layui-icon layui-icon-add-circle"></i>
        文件增加积分
    </button>
    <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="import1">
        <i class="layui-icon layui-icon-reduce-circle"></i>
        文件减少积分
    </button>
</script>
<script type="text/html" id="user-bar">
    <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="view"><i class="layui-icon layui-icon-search "></i></button>
    <button class="pear-btn pear-btn-sm" id="more_{{d.uid}}"><i class="layui-icon layui-icon-triangle-d"></i></button>
</script>
{include file="_Fragment/javascript" /}
<script>
    layui.use(['table', 'form', 'jquery', 'common', 'laydate', 'dropdown'], function() {
        let table = layui.table;
        let form = layui.form;
        let common = layui.common;
        let laydate = layui.laydate;
        let dropdown = layui.dropdown;
        let $ = layui.jquery;

        laydate.render({
            elem: '#date'
            ,range: true //或 range: '~' 来自定义分割字符
            ,trigger: 'click'
            ,type: 'date'
        });

        let cols = [
            [
                {
                    title: '工号',
                    field: 'userid',
                    align: 'center'
                },
                {
                    title: '姓名',
                    field: 'name',
                    align: 'center',
                },
                {
                    title: '当前积分',
                    field: 'rest_num',
                    align: 'center',
                    sort: true
                },
                {
                    title: '积分消耗',
                    field: 'use_num',
                    align: 'center',
                    sort: true
                },

                {
                    title: '积分获取',
                    field: 'get_num',
                    align: 'center',
                    sort: true
                },

                {
                    title: '操作',
                    toolbar: '#user-bar',
                    align: 'center',
                    width: 130
                }
            ]
        ]

        table.render({
            elem: '#user-table',
            url: '/IntegralRecord/getUserRecordList',
            page: {layout:['count', 'prev', 'page', 'next', 'skip']},
            limit: 10,
            cols: cols,
            //skin: 'line',
            toolbar: '#user-toolbar',
            defaultToolbar: [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter'],
            done: function(res, curr, count) {
                for (var i = 0; i < res.data.length; i++) {
                    dropdown.render({
                        elem: '#more_' + res.data[i].uid,
                        data: [{
                            title: '调整',
                            uid: res.data[i].uid,
                            type: 1,
                        }],
                        id: '#more_' + res.data[i].uid,
                        click: function(obj) {
                            if (obj.type == 1) {
                                layer.open({
                                    type: 2,
                                    title: '调整',
                                    shade: 0.1,
                                    area: [common.isModile()?'100%':'900px', common.isModile()?'100%':'600px'],
                                    content: '/IntegralRecord/changeAmount?uid='+obj.uid
                                });
                            }
                        }
                    });
                }
            }
        });

        form.on('submit(user-query)', function(data) {
            table.reload('user-table', {
                where: data.field
                ,page: {
                    curr: 1, //重新从第 1 页开始
                    layout:['count', 'prev', 'page', 'next', 'skip']
                }
                ,limit: 10,
            })
            return false;
        });

        //监听排序事件
        table.on('sort(user-table)', function(obj){ //注：sort 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            table.reload('user-table', {
                initSort: obj //记录初始排序，如果不设的话，将无法标记表头的排序状态。
                ,where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                    field: obj.field //排序字段
                    ,order: obj.type //排序方式
                }
            });
        });


        table.on('tool(user-table)', function(obj) {
            if (obj.event === 'view') {
                window.view(obj);
            }
        });

        table.on('toolbar(user-table)', function(obj) {
            if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'import') {
                window.import();
            } else if (obj.event === 'import1') {
                window.import1();
            }
        });

        window.import = function() {
            layer.open({
                type: 2,
                title: '文件增加积分',
                shade: 0.1,
                area: [common.isModile()?'100%':'900px', common.isModile()?'100%':'600px'],
                content: '/IntegralRecord/import'
            });
        }

        window.import1 = function() {
            layer.open({
                type: 2,
                title: '文件减少积分',
                shade: 0.1,
                area: [common.isModile()?'100%':'900px', common.isModile()?'100%':'600px'],
                content: '/IntegralRecord/import1'
            });
        }

        window.refresh = function(param) {
            table.reload('user-table');
        }

        window.view = function(obj) {
            layer.open({
                type: 2,
                title: '用户详情',
                shade: 0.1,
                area: [common.isModile()?'100%':'900px', common.isModile()?'100%':'600px'],
                content: '/IntegralRecord/userDetail?uid='+obj.data.uid
            });
        }

    })
</script>
</body>
</html>
